/*
 *  lang.c
 *
 *
 * Copyright (c) 2006 Karlan Thomas Mitchell<karlanmitchell@gmail.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, is not permitted.
 */


#include "lang.h"

int lang_init(struct st_lang * language_struct, char * programmers_lang_code){
	language_struct->lang             = NULL;
	language_struct->programmers_lang = (char *)malloc((strlen(programmers_lang_code) + 1) * sizeof(char));
	strcpy(language_struct->programmers_lang, programmers_lang_code);

	mdb_init(&(language_struct->data_struct));
}

int lang_free(struct st_lang * language_struct){
	free(language_struct->lang);
	free(language_struct->programmers_lang);
	mdb_free(&(language_struct->data_struct));
}

int lang_load(struct st_lang * language_struct, char * filename, char * lang_code){
	language_struct->lang = (char *)malloc( (strlen(lang_code) + 1) * sizeof(char) );
	strcpy(language_struct->lang, lang_code);

	mdb_load(&(language_struct->data_struct), filename);
}

char * lang_print(struct st_lang * language_struct, char * word){
	if(language_struct->lang == NULL)
		return word;
	if(strcmp(language_struct->lang, language_struct->programmers_lang) == 0)
		return word;

	char * translation = mdb_get(&(language_struct->data_struct), word);
	if(translation == NULL)
		return word;
	return translation;
}
